﻿using System;
using System.ComponentModel;
using System.ServiceModel.DomainServices.Client;

namespace RiaMVVM
{
	/// <summary>
	/// A simple base class for ViewModels that implements INotifyPropertyChanged.
	/// </summary>
	public abstract class ViewModel : INotifyPropertyChanged
	{
		#region INotifyPropertyChanged values

		public event PropertyChangedEventHandler PropertyChanged;

		protected void RaisePropertyChanged(string propertyName)
		{
			var handler = PropertyChanged;
			if (handler != null)
			{
				handler(this, new PropertyChangedEventArgs(propertyName));
			}
		}
		#endregion
	}

	/// <summary>
	/// A simple base class for ViewModels that require a DomainContext
	/// </summary>
	/// <typeparam name="TContext"></typeparam>
	public abstract class ViewModel<TContext> : ViewModel where TContext : DomainContext
	{
		protected TContext Context { get; set; }

		protected ViewModel(TContext context)
		{
			Context = context;
		}
	}
}
